package com.zhuoyue.biz.core.command.impl.lock;

import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.zhuoyue.biz.core.command.model.LockCmd;
import com.zhuoyue.common.utils.DataTypeUtil;

/**
 * 六孚指纹锁控制类
 *
 * @author Administrator
 */
public class FingerprintLock0Fbe0203 {
    private static final int PSD_SIZE = 6;
    private static final String CMD_MODEL = "0701${gatewayMac}${deviceMac}0B80081080${psd}${check}";

    public static String getCommand(String controlParam) {
        Map<String, String> map = (Map) JSONObject.parse(controlParam);

        Map<String, String> actionsMap = (Map) JSONObject.parse(JSON.toJSONString(map.get("actions")));

        String password = actionsMap.get("password");

        StringBuffer sb = new StringBuffer("");
        for (int i = 0; i < PSD_SIZE; i++) {
            sb.append("0" + password.subSequence(i, i + 1));
        }

        String addCheck = DataTypeUtil.getAddCheckByXor("1080" + sb.toString());
        return new LockCmd(map.get("gatewayMac"), map.get("deviceMac"), sb.toString(), addCheck).getCmd(CMD_MODEL);
    }
}
